package org.kabeja.parser.objects;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.objects.DXFObject;
import org.kabeja.dxf.objects.DXFPlotSettings;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 12:13
 */
public class DXFPlotsettingsHandler extends AbstractDXFObjectHandler {
    public static final int GROUPCODE_NAME = 1;
    public static final int GROUPCODE_PLOT_CONFIGURATION_FILE = 2;
    public static final int GROUPCODE_PAPER_SIZE = 4;
    public static final int GROUPCODE_PLOT_VIEW_NAME = 6;
    public static final int GROUPCODE_MARGIN_LEFT = 40;
    public static final int GROUPCODE_MARGIN_BOTTOM = 41;
    public static final int GROUPCODE_MARGIN_RIGHT = 42;
    public static final int GROUPCODE_MARGIN_TOP = 43;
    public static final int GROUPCODE_PLOT_PAPER_WIDTH = 44;
    public static final int GROUPCODE_PLOT_PAPER_HEIGHT = 45;
    public static final int GROUPCODE_ORIGIN_X = 46;
    public static final int GROUPCODE_ORIGIN_Y = 47;
    public static final int GROUPCODE_PLOT_WINDOW_MIN_X = 48;
    public static final int GROUPCODE_PLOT_WINDOWS_MIN_Y = 49;
    public static final int GROUPCODE_PLOT_WINDOW_MAX_X = 140;
    public static final int GROUPCODE_PLOT_WINDOWS_MAX_Y = 141;
    public static final int GROUPCODE_CUSTOM_SCALE_NUMERATOR = 142;
    public static final int GROUPCODE_CUSTOM_SCALE_DEOMINATOR = 143;
    public static final int GROUPCODE_PAPER_UNITS = 72;
    public static final int GROUPCODE_PLOT_ROTATION = 73;
    public static final int GROUPCODE_PLOT_TYPE = 74;
    public static final int GROUPCODE_CURRENT_STYLESHEET = 7;
    public static final int GROUPCODE_STANDARD_SCALE_TYPE = 75;
    protected DXFPlotSettings plotSettings;

    public DXFPlotsettingsHandler() {
    }

    @Override
    public void endObject() {
    }

    @Override
    public DXFObject getDXFObject() {
        return this.plotSettings;
    }

    @Override
    public String getObjectType() {
        return DXFConstants.OBJECT_TYPE_PLOTSETTINGS;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        double[] var3;
        switch(var1) {
            case GROUPCODE_NAME:
                this.plotSettings.setName(var2.getValue());
                break;
            case GROUPCODE_PLOT_CONFIGURATION_FILE:
            case GROUPCODE_PAPER_SIZE:
                break;
            case GROUPCODE_PLOT_VIEW_NAME:
                this.plotSettings.setPlotViewName(var2.getValue());
                break;
            case GROUPCODE_CURRENT_STYLESHEET:
                this.plotSettings.setCurrentStylesheet(var2.getValue());
                break;
            case GROUPCODE_MARGIN_LEFT:
                var3 = this.plotSettings.getMargin();
                var3[3] = var2.getDoubleValue();
                this.plotSettings.setMargin(var3);
                break;
            case GROUPCODE_MARGIN_BOTTOM:
                var3 = this.plotSettings.getMargin();
                var3[2] = var2.getDoubleValue();
                this.plotSettings.setMargin(var3);
                break;
            case GROUPCODE_MARGIN_RIGHT:
                var3 = this.plotSettings.getMargin();
                var3[1] = var2.getDoubleValue();
                this.plotSettings.setMargin(var3);
                break;
            case GROUPCODE_MARGIN_TOP:
                var3 = this.plotSettings.getMargin();
                var3[0] = var2.getDoubleValue();
                this.plotSettings.setMargin(var3);
                break;
            case GROUPCODE_PLOT_PAPER_WIDTH:
                this.plotSettings.setPaperWidth(var2.getDoubleValue());
                break;
            case GROUPCODE_PLOT_PAPER_HEIGHT:
                this.plotSettings.setPaperHeight(var2.getDoubleValue());
                break;
            case GROUPCODE_ORIGIN_X:
                this.plotSettings.getPlotOrigin().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_ORIGIN_Y:
                this.plotSettings.getPlotOrigin().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_PLOT_WINDOW_MIN_X:
                this.plotSettings.getWindowToPlot().setMinimumX(var2.getDoubleValue());
                break;
            case GROUPCODE_PLOT_WINDOWS_MIN_Y:
                this.plotSettings.getWindowToPlot().setMinimumY(var2.getDoubleValue());
                break;
            case GROUPCODE_PAPER_UNITS:
                this.plotSettings.setPaperUnit(var2.getIntegerValue());
                break;
            case GROUPCODE_PLOT_ROTATION:
                this.plotSettings.setPlotRotation(var2.getIntegerValue());
                break;
            case GROUPCODE_PLOT_TYPE:
                this.plotSettings.setPlotType(var2.getIntegerValue());
                break;
            case GROUPCODE_PLOT_WINDOW_MAX_X:
                this.plotSettings.getWindowToPlot().setMaximumX(var2.getDoubleValue());
                break;
            case GROUPCODE_PLOT_WINDOWS_MAX_Y:
                this.plotSettings.getWindowToPlot().setMaximumY(var2.getDoubleValue());
                break;
            case GROUPCODE_CUSTOM_SCALE_NUMERATOR:
                this.plotSettings.setCustomScaleNumerator(var2.getDoubleValue());
                break;
            case GROUPCODE_CUSTOM_SCALE_DEOMINATOR:
                this.plotSettings.setCustomScaleDenominator(var2.getDoubleValue());
                break;
            default:
                super.parseCommonGroupCode(var1, var2, this.plotSettings);
        }

    }

    @Override
    public void startObject() {
        this.plotSettings = new DXFPlotSettings();
    }
}
